package com.t;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.TreeSet;

public class TTestExtends<T extends Collection<String>> {
	private T t;
	
	@SuppressWarnings("unchecked")
	public TTestExtends(){
		this.t = (T) new TreeSet<String>();
	} 
	
	public TTestExtends(T t){
		this.t = t;
	}

	public T getT() {
		return t;
	}

	public void setT(T t) {
		this.t = t;
	}
	
	@SuppressWarnings("hiding")
	public <T> int display(T t){
		System.out.println(t.getClass().getName());
		return 0;
	}
	
	
	public static void main(String[] args){
		TTestExtends<Collection<String>> collT = new TTestExtends<Collection<String>>(new ArrayList<String>());
		collT.getT().add("3");
		collT.getT().add(new String("abc"));
		
		
		TTestExtends<Collection<String>> collT1 = new TTestExtends<Collection<String>>();
		collT1.getT().add("str 111");
		collT1.getT().add("str 1111");
		collT1.getT().add("str 11111");
		
		for(Iterator<String> it = collT1.getT().iterator(); it.hasNext();){
			String str = it.next();
			
			System.out.println(str);
		}

		
		
		System.out.println(collT.getT().toString());
		
		TTestExtends<ArrayList<String>> strT = new TTestExtends<ArrayList<String>>(new ArrayList<String>());
		
		strT.getT().add("str");
		strT.getT().add("str2222");
		
		System.out.println(strT.getT().toString());
		
		//向下兼容
		TTestExtends<? extends Collection<String>> strT1 = new TTestExtends<ArrayList<String>>(new ArrayList<String>());
		strT1.getT().add("str333");
		strT1.getT().add("str33333333");
		
		System.out.println(strT1.getT());
		
		
		//向上兼容
		//TTestExtends< ? super Object> ob = new TTestExtends<Object>(new Object());
		
		System.out.println(strT1.display("a"));
		
	}

}
